package org.link.dao;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.link.bean.Page;
import org.link.bean.User;
import org.link.mapper.UserMapper;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao implements UserMapper {

	@Resource
	private SqlSessionFactory sessionFactory;
	
	/**
	 * 添加用户
	 */
	public void addUser(User user) {
		SqlSession session = sessionFactory.openSession();
		UserMapper userMapper = session.getMapper(UserMapper.class);
		userMapper.addUser(user);
		session.close();
	}

	/**
	 * 
	 */
	public List<User> selectUserByLimit(Page page) {
		SqlSession session = sessionFactory.openSession();
		UserMapper userMapper = session.getMapper(UserMapper.class);
		List<User> users = userMapper.selectUserByLimit(page);
		session.close();
		return users;
	}
	
	/**
	 * 
	 */
	public int selectCount() {
		SqlSession session = sessionFactory.openSession();
		UserMapper userMapper = session.getMapper(UserMapper.class);
		int resunt = userMapper.selectCount();
		session.close();
		return resunt;
	}

}
